<?php 
$id = $_REQUEST['id'];
If (strlen($id) <= 0){
	header("Location:roleManager.php");
}
	require('../includes/manager_fns.php');
	$fileName = end(explode('/',$_SERVER['PHP_SELF']));
	$title = '权限管理'; 
	$act = $_REQUEST['act'];
	$conn = db_connect();

	switch($act){
		//编辑权限
		case 'modup';
		
		$module_purview = array();
		if(isset($_POST['module_purview'])){
			$module_purview = $_POST['module_purview'];
		}
		$x = 0;
		foreach($module_purview as $mycheckbox){
			$x += 1;
			//echo $mycheckbox.'<br>';
			if($x == 1){
				$module_purview_array = $mycheckbox;
			}else{
				$module_purview_array = $module_purview_array.','.$mycheckbox;
			}
		}
			//echo $module_purview_array;

		$sql = 'UPDATE `role` SET `module_purview` = :purview WHERE `role_id` = :id';
		$stmt2 = $conn -> prepare($sql);
		$stmt2 -> bindParam(':id',$id);
		$stmt2 -> bindParam(':purview',$module_purview_array);
		$stmt2 -> execute();
		echo '<script>alert(\'提交成功!\');location.href = \''.$fileName.'?id='.$id.'\';</script>';
		
		break;
		default:
			//取默认值
			$sql = 'SELECT `module_purview` FROM `role` WHERE `role_id` = :id';
			$stmt2 = $conn -> prepare($sql);
			$stmt2 -> bindParam(':id',$id);
			$stmt2 -> execute();
			$vo2 = $stmt2 -> fetchColumn();
			
			
	}
	//}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $title ?></title>
<script src="js/manager.js" type="text/javascript"></script>
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	background-color: #F8F9FA;
}
-->
</style>
<link href="images/skin.css" rel="stylesheet" type="text/css" />
</head>

<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="17" height="29" valign="top" background="images/mail_leftbg.gif"><img src="images/left-top-right.gif" width="17" height="29" /></td>
    <td height="29" valign="top" background="images/content-bg.gif"><table width="100%" height="31" border="0" cellpadding="0" cellspacing="0" class="left_topbg" id="table2">
        <tr>
          <td height="31"><div class="titlebt"><?php echo $title ?></div></td>
        </tr>
      </table></td>
    <td width="16" valign="top" background="images/mail_rightbg.gif"><img src="images/nav-right-bg.gif" width="16" height="29" /></td>
  </tr>
  <tr>
    <td height="71" valign="middle" background="images/mail_leftbg.gif">&nbsp;</td>
    <td valign="top" bgcolor="#F7F8F9"><table width="100%" height="138" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td height="13" valign="top">&nbsp;</td>
        </tr>
        <tr>
          <td valign="top"><table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
              <tr>
                <td class="left_txt">当前位置：<?php echo $title ?></td>
              </tr>
              <tr>
                <td height="20"><table width="100%" height="1" border="0" cellpadding="0" cellspacing="0" bgcolor="#CCCCCC">
                    <tr>
                      <td></td>
                    </tr>
                  </table></td>
              </tr>
              <tr>
                <td><table width="100%" height="55" border="0" cellpadding="0" cellspacing="0">
                    <tr>
                      <td width="10%" height="55" valign="middle"><img src="images/title.gif" width="54" height="55"></td>
                      <td width="90%" valign="top"><span class="left_txt2">网站后台角色权限的管理</span><br>
                        <span class="left_txt2">包括</span><span class="left_txt3">管理员角色权限的修改</span>。 </span></td>
                    </tr>
                  </table></td>
              </tr>
              <tr>
                <td>&nbsp;</td>
              </tr>
            </table>
            <table width="100%" border="0" cellpadding="0" cellspacing="0">
              <form name="modform" action="" method="post" />
              <input name="act" value="modup" type="hidden" />
              <tr>
                <td colspan="2" align="center" bgcolor="#f2f2f2" class="left_txt"><table width="100%" height="31" border="0" cellpadding="0" cellspacing="0" class="nowtable">
                    <tr>
                      <td class="left_bt2" align="left">&nbsp;&nbsp;&nbsp;&nbsp;编辑权限</td>
                    </tr>
                  </table></td>
              </tr>
              <tr bgcolor="#f2f2f2">
                <th align="center" class="left_txt2">模块组</th>
                <th align="center" class="left_txt2">模块</th>
              </tr>
<?php 
            $conn = db_connect();
            $sql = 'SELECT * FROM `module_group` ORDER BY `module_group_order`';
            $stmt = $conn -> prepare($sql);
            $stmt -> execute();
            $vo = $stmt -> fetchall();
            $i = 0;
            foreach ($vo as $value){
            	$i += 1;
            	if (fmod($i,2) == 0){
            		$bgcolor = '#f2f2f2';
            	}else{
            		$bgcolor = '';
            	}
            	$sql1 = 'SELECT `module_id`,`module_name` FROM `module` WHERE `module_group_id` = :id ORDER BY `module_order`';
               	$stmt1 = $conn -> prepare($sql1);
       			$stmt1 -> bindParam(':id',$value['module_group_id']);
       			$stmt1 -> execute();
       			$vo1 = $stmt1 -> fetchAll();
       			$row = count($vo1);
            	
            	//$rowC = $stmt1 -> rowCount();

?>
              <tr bgcolor="<?php echo $bgcolor ?>">
                <td width="18%" align="center" class="left_txt2"><?php echo $value['module_group_name'];?></td>
                <td width="82%" align="center" class="left_txt2"><table width="100%" border="0">
                    <tr>
                      <?php table_list(0,3,$vo1,$row,'module_purview[]',':module_id',':module_id','module_name',$vo2); ?>
                    </tr>
                  </table></td>
              </tr>
              <?php 
            }
            ?>
              <tr>
                <td colspan="2" align="center" class="left_txt"><input type="image" src="images/tj.jpg" name="submit"/></td>
              </tr>
              </form>
            </table></td>
        </tr>
      </table></td>
    <td background="images/mail_rightbg.gif">&nbsp;</td>
  </tr>
  <tr>
    <td valign="middle" background="images/mail_leftbg.gif"><img src="images/buttom_left2.gif" width="17" height="17" /></td>
    <td height="17" valign="top" background="images/buttom_bgs.gif"><img src="images/buttom_bgs.gif" width="17" height="17" /></td>
    <td background="images/mail_rightbg.gif"><img src="images/buttom_right2.gif" width="16" height="17" /></td>
  </tr>
</table>
</body></html>
